package com.pda.xinma.presenter;

import com.pda.xinma.bean.BackInfoBean;
import com.pda.xinma.bean.ManifestListBean;
import com.pda.xinma.bean.OutSignBean;
import com.pda.xinma.bean.TabEvent;
import com.pda.xinma.contract.InventoryContract;
import com.pda.xinma.net.NetUtils;
import com.wangshen.base.net.bean.BaseAppEntity;
import com.wangshen.base.net.bean.BaseRowsAppEntity;
import com.wangshen.base.ui.mvp.base.presenter.BasePresenter;

import org.greenrobot.eventbus.EventBus;

import java.util.List;

import io.reactivex.functions.Consumer;

public class InventoryPresenter extends BasePresenter<InventoryContract.View> implements InventoryContract.Presenter {
    @Override
    public void manifestList(String taskNo,int pager) {
        NetUtils.geApi().manifestList(taskNo,pager,10)
                .compose(this.handleEverythingResult())
                .subscribe(new Consumer<BaseRowsAppEntity<List<ManifestListBean>>>() {
                    @Override
                    public void accept(BaseRowsAppEntity<List<ManifestListBean>> listBaseRowsAppEntity) throws Exception {
                        getView().setDataList(listBaseRowsAppEntity.getRows());
                    }
                }, new Consumer<Throwable>() {
                    @Override
                    public void accept(Throwable throwable) throws Exception {
                        getView().showMessage(throwable.getMessage());
                    }
                });
    }

    @Override
    public void callTakeDown(String taskDetailId, String rollerId) {
        NetUtils.geApi().callTakeDown(taskDetailId, rollerId)
                .compose(this.handleEverythingResult())
                .subscribe(new Consumer<BaseAppEntity<BackInfoBean>>() {
                    @Override
                    public void accept(BaseAppEntity<BackInfoBean> backInfoBeanBaseAppEntity) throws Exception {
                        getView().showMessage(backInfoBeanBaseAppEntity.getMsg());
                        EventBus.getDefault().post(new TabEvent(1));
                    }
                }, new Consumer<Throwable>() {
                    @Override
                    public void accept(Throwable throwable) throws Exception {
                        getView().showMessage(throwable.getMessage());
                    }
                });
    }

    @Override
    public void getAllCallTakeDown(String taskNo, String rollerId) {
        NetUtils.geApi().getAllCallTakeDown(taskNo)
                .compose(this.handleEverythingResult())
                .subscribe(new Consumer<BaseAppEntity<OutSignBean>>() {
                    @Override
                    public void accept(BaseAppEntity<OutSignBean> backInfoBeanBaseAppEntity) throws Exception {
                        getView().showMessage(backInfoBeanBaseAppEntity.getMsg());
                        EventBus.getDefault().post(new TabEvent(1));
                    }
                }, new Consumer<Throwable>() {
                    @Override
                    public void accept(Throwable throwable) throws Exception {
                        getView().showMessage(throwable.getMessage());
                    }
                });
    }
}
